package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.modular.ctm.entity.UserInfo;
import cn.stylefeng.guns.modular.ctm.service.UserInfoService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 用户管理
 */
@Controller
@RequestMapping("/api/user")
@Api(tags = "用户管理")
public class ApiUserInfoController extends BaseController {

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/queryInfo")
    @ResponseBody
    public ResponseData queryInfo() {
        return ResponseData.success(userInfoService.userInfo());
    }

    @PostMapping("/save")
    @ApiOperation(value = "个人信息保存", notes = "个人信息保存")
    @ResponseBody
    public ResponseData save(@RequestBody UserInfo userInfo) {
        boolean flag = false;
        if (StringUtils.isBlank(userInfo.getId()) && !StringUtils.isBlank(userInfo.getName())) {
            flag = userInfoService.save(userInfo);
        } else if (!StringUtils.isBlank(userInfo.getId())) {
            flag = userInfoService.updateById(userInfo);
        }
        return ResponseData.success(flag);
    }

}